package br.com.cdto.DAO;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import br.com.cdto.entity.Receptor;

/**
 * Session Bean implementation class ReceptorDAO
 */
@Stateless
@LocalBean
public class ReceptorDAO implements ReceptorDAOLocal {
	@PersistenceContext
	public EntityManager entityManager;
	
    public ReceptorDAO() {
    }

	@Override
	public void salvaReceptor(Receptor r) {
		entityManager.persist(r);
	}

	@Override
	public List<Receptor> consultaReceptor(String sql, String tipoCornea) {
		sql = "SELECT r FROM Receptor r" + sql + "ORDER BY r.dataInscricao ASC LIMIT 25";
		TypedQuery<Receptor> query = entityManager.createQuery(sql, Receptor.class);
		query.setParameter("tipoCornea", tipoCornea);
		List<Receptor> list = query.getResultList();
		for (Receptor receptor : list) {
			System.out.println(receptor.getEquipe());
			System.out.println(receptor.getEquipe().getEmailEquie());
		}
		return list;
	}
    
    

}
